<?php
class Home extends MX_Controller
{
    function __construct()
    {
        parent::__construct();                     
    }
    function index()
    {
        // get restaurentmenu                                                                                         
        $term = new Term_taxonomy();
        $term->include_related('term', array('id', 'name','slug'))->get_by_term_id(55);
        $data['term'] = $term; 
        // Lay ra danh sach mon an cua thuc don
        $list_child_product = new Product();                   
        if($term->term_id>0)
        {
            $list_child_product->include_related('term_taxonomy',array('term_id','taxonomy'))
                    ->where_related('term_taxonomy', 'taxonomy', 'restaurentmenu')
                    ->where_related('term_taxonomy', 'term_id', $term->term_id);  
            //$list_child_product->include_related('term_taxonomy_product',array('term_order'));                                   
        }
        $list_child_product->select('hd_term_taxonomies_products.term_order');
        $list_child_product->select('hd_term_taxonomies_products.id AS term_tax_product_id');
        $list_child_product->order_by('hd_term_taxonomies_products.term_order','ASC');
        $data['list_child_product'] = $list_child_product->get();
        
        $term = new Term_taxonomy();
        $term->include_related('term', array('id', 'name','slug'))->get_by_term_id(50);
        $data['term'] = $term; 
        // Lay ra danh sach nha hang cua danh muc nha hang
        $list_child_restaurent = new Restaurent();                       
        if($term->term_id>0)
        {
            $list_child_restaurent->include_related('term_taxonomy',array('term_id','taxonomy'))
                    ->where_related('term_taxonomy', 'taxonomy', 'categoryrestaurent')
                    ->where_related('term_taxonomy', 'term_id', $term->term_id);                  
        }
        $list_child_restaurent->select('hd_term_taxonomies_restaurents.term_order');
        $list_child_restaurent->select('hd_term_taxonomies_restaurents.id AS term_tax_restaurent_id');
        $list_child_restaurent->order_by('hd_term_taxonomies_restaurents.term_order','ASC');
        $data['list_child_restaurent'] = $list_child_restaurent->get();  
        $data['flag'] = 1;
        // check login
        if(!$this->session->userdata('login'))
        {
            $data['check_login'] = false;
        }
        else 
        {
            $data['check_login'] = true;
        }
        
        $this->common->load_template('home_index',$data);
    }      
    function get_district()
    {        
        $province_id = $this->input->post('province_id');                
        $district = new District();        
        $district->where('province_id',$province_id)->get();  
        $data = '<option value = "0">Quận</option>';
        foreach ($district as $item)
        {
            $data.='<option  value="'.$item->id.'">'.$item->name.'</option>';
        }
        echo $data;
    }
    
    function test()
    {
        $product = new Product();                  
        $product->where('id', 12);
        $product->include_related('term_taxonomy',array('term_id','taxonomy'))
                ->where_related('term_taxonomy', 'taxonomy', 'wishlistproduct')
                ->where_related('term_taxonomy', 'user_id',1);                  
                
        $list_child_product = $product->count();  
        
        echo $list_child_product;
    }
}
?>